﻿using DataStatisticsChartModule.Views;
using LPLS.DBEntities.ConfigModels.DeviceInfoModels;
using LPLS.DBInterface.ConfigModels.DeviceInfoModels;
using LPLS.PluginCommon;
using LPLS.PluginCommon.ModulePlugin;
using LPLS.WPFBaseLibrary;
using Prism.Commands;
using Prism.Dialogs;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace DataStatisticsChartModule.ViewModels
{

    [ViewModelMetadata(projectID: "12322222", viewModelName: "组件数据统计", version: "1.0.1", lifecycle: Lifecycle.Singleton, index: 0, isCommon: true)]
    public class DataStatisticsSummaryViewModel : ViewModelBase
    {
      
        IDeviceBaseInfoService _deviceBaseInfoService;

        private readonly IContainerProvider _container;
        public DataStatisticsSummaryViewModel(IContainerProvider containerProvider, IDeviceBaseInfoService deviceBaseInfoService) : base(containerProvider)
        {
            _container= containerProvider;
            _deviceBaseInfoService = deviceBaseInfoService;       
            QueryCommand = new DelegateCommand(QueryData);
            InitializeTabs();
            LoadData();
        }

        private void QueryData()
        {
            var dialogService = _container.Resolve<IDialogService>();
            if (StartDate>EndDate)
            {
                MessageBox.Show("起时间大于止时间");
                return;
            }
            if (SelectDeviceModel == null)
            {

                MessageBox.Show("未选择设备");
                //dialogService.ShowMessageTip("未选择设备", "提示");
                return;
            }
            DataStatisticsEvent.RaiseDataStatisticsEvent(new DataStatisticsEventModel()
            {
                DeviceModel = SelectDeviceModel,
                StartTime = StartDate,
                EndTime = EndDate.AddDays(1)
            });
        }

        private ObservableCollection<TabItem> _tabItems;
        public ObservableCollection<TabItem> TabItems
        {
            get { return _tabItems; }
            set { SetProperty(ref _tabItems, value); }
        }

        private void InitializeTabs()
        {
            TabItems = new ObservableCollection<TabItem>
        {
              CreateTabItem("组件状态统计", typeof(TubeDataStatisticsChartView)),
              CreateTabItem("报警代码统计", typeof(AlarmDataStatisticsChartView)),
                CreateTabItem("时间稼动率配置", typeof(TimeUtilizationRateConfigView)),
                  CreateTabItem("时间稼动率配置", typeof(TimeUtilizationView))



                
        };
        }
        #region  设备数据加载 条件筛选
        /// <summary>
        /// 
        /// </summary>
        private void LoadData()
        {
            this.StartDate = DateTime.Now.AddDays(-1);
            this.EndDate = DateTime.Now;
            DeviceList = new ObservableCollection<DeviceBaseInfo>(_deviceBaseInfoService.GetData());




        }

        private ObservableCollection<DeviceBaseInfo> _DeviceList;

        public ObservableCollection<DeviceBaseInfo> DeviceList
        {
            get { return _DeviceList; }
            set
            {
                SetProperty(ref _DeviceList, value);

            }
        }

        private DeviceBaseInfo _SelectDeviceModel;
        public DeviceBaseInfo SelectDeviceModel
        {
            get { return _SelectDeviceModel; }
            set
            {

                SetProperty(ref _SelectDeviceModel, value);

            }
        }


        private DateTime _StartDate;

        public DateTime StartDate
        {
            get { return _StartDate; }
            set
            {

                SetProperty(ref _StartDate, value);
            }
        }

        private DateTime _EndDate;

        public DateTime EndDate
        {
            get { return _EndDate; }
            set
            {

                SetProperty(ref _EndDate, value);
            }
        }



        #endregion

        public DelegateCommand QueryCommand { get; }





















    }
}
